#ifndef MAINAPP_H
#define MAINAPP_H

#include <QObject>

#include "CommonType.h"
#include <QPixmap>
#include <QMutex>

#include "CSerialCommandWrapper.h"

//class HomeWnd;
class BannerWnd;
class MainWnd;
class BackendWnd;

class QStackedWidget;

using namespace zl;
class MainApp : public QObject
{
    Q_OBJECT
public:
    static MainApp* Instance();
    static void Release();

    int32_t Run();

    QWidget* GetBaseWidget(){ return (QWidget*)base_widget_;}

    // 获取当前前端操作步骤
    EWF CurrentWorkFlow() { return m_workflow_status;}

    // 获取当前监控板串口连接对象
    CSerialCommandWrapper* GetSerialConnectObj() { return serial_connect_;}

    // 当前是否显示后台
    bool Is_backend_show();

protected:

    enum EViewType {
        EViewType_Home      = 0,
        EViewType_Main      = 1,
        EViewType_Backend   = 2
    };

    void set_current_view(EViewType type);

    void init_view();

    void init_configuration();
    void init_database();

    void init_serial_connect();

    void serial_port_connect();

    void init_nrfjprog_mgr_config();

    void exit_application();

    void update_app_configuration();

    bool eventFilter(QObject *watched, QEvent *event) override;

private:
    MainApp();
    ~MainApp();

private slots:

    void event_work_flow_change(zl::EWF workFlow);

    void event_backend_page_change(zl::EBP backendPage);

    void event_select_language(zl::ELanguageType type);

    void event_enter_backend();

    void event_config_changed();

    void event_serial_command_result(const unsigned char cmd, zl::zlmodules::CommandResultType type, QByteArray data);

    void event_serial_msg_data(const unsigned char cmd, QByteArray data);

public:

    QStackedWidget*         base_widget_;
    QStackedWidget*			container_;

    MainWnd*				main_wnd_;
    BannerWnd*              banner_wnd_;
    BackendWnd*             backend_wnd_;

private:
    static MainApp*			Instance_;

    EWF						m_workflow_status;                  // 前端当前操作步骤

    // 当前串口设备的连接对象
    CSerialCommandWrapper*      serial_connect_;                // 监控板串口连接对象
};

#endif // MAINAPP_H
